<?
function site_name() {
	$site_name = get_global_options("site_name");
	return $site_name;
}

function site_description() {
	$site_description = get_global_options("site_description");
	return $site_description;
}

function recent_posts($limit = 5, $list_type = "ul", $list_item_before = "<li>", $list_item_after = "</li>") {
	if(substr($list_type, 0, 1) == "<") {
		$list_type = substr($list_type, 1);
	}
	if(substr($list_type, -1, 1) == ">") {
		$list_type = substr($list_type, 0, (strlen($list_type) - 1));
	}
	$the_posts = get_the_posts($limit, 0, "publish,private", "blog,aside");
	echo "<" . $list_type . " id=\"recent_posts\">\n";
	foreach($the_posts as $the_post) {
		echo $list_item_before . "<a href=\"/blog/" . $the_post['permalink_name'] . "\" title=\"" . $the_post['title'] . "\">" . $the_post['title'] . "</a>" . $list_item_after . "\n";
	}
	echo "</" . $list_type . ">\n";
}

function the_theme($option = null) {
	global $drizzo_options;
	
	use_db_drizzo();
	
	$theme_lookup = mysql_query("SELECT `value` FROM `$drizzo_options` WHERE `name`='theme'");
	if($theme_lookup) {
		$theme_name = mysql_fetch_array($theme_lookup);
		$theme_name = $theme_name[0];
	} else {
		$theme_name = "default";
	}
	
	if(!$option) {
		return $theme_name;
	}
	
	if(($option == "stylesheet")|| ($option == "css")) {
		$stylesheet = "http://" . domain_name . "/drizzo-themes/" . $theme_name . "/style.css";
		return $stylesheet;
	}
	
	if($option == "directory") {
		$directory = "http://" . domain_name . "/drizzo-themes/" . $theme_name . "/";
		return $directory;
	}

	if($option == "local_dir") {
		$directory = $_SERVER['DOCUMENT_ROOT'] . "/drizzo-themes/" . $theme_name . "/";
		return $directory;
	}
}

function drizzo_startup() {
	if(config_file_check()) {
		update_version_number();
		login();
		fetch_user_info();
		get_page_id();
		get_page_type();
	}
}

function parse_the_uri() {
	if(!$_GET) {
		$doc_root = $_SERVER['DOCUMENT_ROOT'];
		$req_uri = $_SERVER['REQUEST_URI'];
		$scpt = $_SERVER['SCRIPT_FILENAME'];

		$url = strip_tags($req_uri);
		$url_array = explode("/",$url);
		array_shift($url_array); //the first one is empty anyway

		if(!empty($url_array)) {
			$final = count($url_array) - 1;
			if(empty($url_array[$final])) {
				$final = count($url_array) - 2;
			} 

			if($url_array[0] == ("blog" || "page" || "netcasts" || "asides" || "events")) {
				$drizzo_page_type = $url_array[0];
				$drizzo_post_id = $url_array[$final];
			} elseif($url_array[0] == "archive") {
				$drizzo_page_type = "archive";
				$drizzo_offset = $url_array[1] * 10;
			} else {
				$drizzo_post_id = $url_array[0];
			}

			$drizzo_uri_vars = array(
				"page_type" => $drizzo_page_type,
				"post_id" => $drizzo_post_id,
				"offset" => $drizzo_offset
				);
			return $drizzo_uri_vars;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
?>